/**
 * @param {string} url
 * @returns {Boolean}
 */
export function validURL(rule, url, callback) {
    const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
    if ((!reg.test(url)) && url != '') {
        callback(new Error('请输入正确的url地址(http/https/ftp://xx.xxx)'));
    } else {
        callback()
    }
}
/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validAlphabets1(rule, str, callback) {
    const reg = /[^\w\.\/]/ig
    if ((!reg.test(str)) && str != '') {
        callback(new Error('请输入数字、26个英文字母或者下划线组成的字符串'));
    } else {
        callback()
    }
}
/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validAlphabets(rule, str, callback) {
    const reg = /((?=.*[a-z])(?=.*\d)|(?=[a-z])(?=.*[#@!~%^&*])|(?=.*\d)(?=.*[#@!~%^&*]))[a-z\d#@!~%^&*]{8,16}/i
    if ((!reg.test(str)) && str != '') {
        callback(new Error('请输入数字、26个英文字母或者特殊字符组成的字符串'));
    } else {
        callback()
    }
}


/**
 * @param {string} email
 * @returns {Boolean}
 */
export function validEmail(rule, value, callback) {
    const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    if (value == '' || value == undefined || value == null) {
        callback();
    } else {
        if ((!reg.test(value)) && value != '') {
            callback(new Error('请输入正确的邮箱地址'));
        } else {
            callback();
        }
    }
}

/**
 * @param {string} idCard
 * @returns {Boolean}
 */
export function validIdCard(rule, value, callback) {
    const reg18 = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
    const reg15 = /^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$/
    if (value == '' || value == undefined || value == null) {
        callback();
    } else {
        if ((reg18.test(value) || reg15.test(value)) && value != '') {
            callback();
        } else {
            callback(new Error('请输入正确的身份证号码'));
        }
    }
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function isString(str) {
    if (typeof str === 'string' || str instanceof String) {
        return true
    }
    return false
}

/**
 * @param {Array} arg
 * @returns {Boolean}
 */
export function isArray(arg) {
    if (typeof Array.isArray === 'undefined') {
        return Object.prototype.toString.call(arg) === '[object Array]'
    }
    return Array.isArray(arg)
}

/**
 * @param {string} pho
 * @returns {Boolean}
 */
export function validatePhone(rule, value, callback) {
    // const reg = /^[1][3-9][0-9]{9}$/;
    const reg = /^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\d{8}$/;
    // /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
    if (value == '' || value == undefined || value == null) {
        callback();
    } else {
        if ((!reg.test(value)) && value != '') {
            callback(new Error('请输入正确的电话号码'));
        } else {
            callback();
        }
    }
}
export function validateNumber(rule, value, callback) {
    const reg = /^[1-9]\d*\,\d*|[1-9]\d*$/;
    if (value == '' || value == undefined || value == null) {
        callback();
    } else {
        if ((!reg.test(value)) && value != '') {
            callback(new Error('请输入正确的数字'));
        } else {
            callback();
        }
    }
}

export function validateCNumber(rule, value, callback) {
    const reg = /^[0-9]\d*$/;
    if (value == '' || value == undefined || value == null) {
        callback();
    } else {
        if ((!reg.test(value)) && value != '') {
            callback(new Error('请输入整数'));
        } else {
            callback();
        }
    }
}

export function validateC(rule, value, callback) {
    const reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
    if (value == '' || value == undefined || value == null) {
        callback();
    } else {
        console.log(reg.test(value));
        if ((!reg.test(value)) && value != '') {
            callback(new Error('请输入正整数'));
        } else {
            callback();
        }
    }
}

export function validateF2(rule, value, callback) {
    const reg = /^\d*(\.\d{1,2})?$/;
    if (value == '' || value == undefined || value == null) {
        callback();
    } else {
        if ((!reg.test(value)) && value != '') {
            callback(new Error('请输入数字并且限制2位小数'));
        } else {
            callback();
        }
    }
}

export function validateUp(rule, value, callback) {
    const reg = /^[A-Z]+$/;
    if (value == '' || value == undefined || value == null) {
        callback();
    } else {
        if ((!reg.test(value)) && value != '') {
            callback(new Error('请输入大写字母'));
        } else {
            callback();
        }
    }
}